/***********************************************************************************************************************************
 * Name:	Replication_Cleanup.sql
 * Author:	Frank Figearo (frank.figearo@us.bbaaviation.com|frank@sqlnerd.me)
 * Summary:	New Script Template
 */
SET IMPLICIT_TRANSACTIONS OFF; IF 0 < @@TRANCOUNT ROLLBACK;
USE [DistributionDB];
GO
CREATE PROCEDURE #ClearSubscriptionArtifacts (@article SYSNAME, @kill BIT = 0, @nuke BIT = 0) AS
DECLARE @artifacts TABLE (article_id INT NOT Null);
INSERT INTO @artifacts SELECT article_id FROM dbo.MSArticles WHERE Article = @article;
SELECT * FROM dbo.MSArticles WHERE article_id IN (SELECT article_id FROM @artifacts);
SELECT * FROM dbo.MSSubscriptions WHERE article_id IN (SELECT article_id FROM @artifacts);
IF @nuke = 1 SET @kill= 1;
IF @kill = 1 DELETE dbo.MSsubscriptions WHERE article_id IN (SELECT article_id FROM @artifacts);
IF @nuke = 1 DELETE dbo.MSArticles WHERE article_id IN (SELECT article_id FROM @artifacts);
GO

EXECUTE #ClearSubscriptionArtifacts N'';
GO